#ifndef _SYS_
#define _SYS_

#include "var.h"
#include "flags.h"

#include <avr/pgmspace.h>
#include <avr/eeprom.h>

#define DEFPARAM(Name,Ini,Min,Max) unsigned long Name;\
  unsigned long min_ ## Name  = Min; \
  unsigned long max_ ## Name  = Max; \
  unsigned long e_ ## Name EEMEM= Ini;

struct Parameter {
  DWORD * Val;
  DWORD Min,Max;
  DWORD * EVal;
  BYTE L;
  };

extern volatile WORD Flags;     
extern volatile WORD PauseCnt;  
extern volatile WORD InpPattrn;
extern volatile WORD InpChange;
extern WORD OutMsk;
extern volatile DWORD StepCounter;
extern BYTE WCounter;
extern enum OpMode Mode;
extern WORD Options;

extern DWORD Counter;

extern WORD  e_Input EEMEM;
extern DWORD e_Counter EEMEM;
extern BYTE  e_Mode EEMEM;
extern BYTE  e_Flags EEMEM;
extern WORD  e_Output EEMEM;
extern DWORD e_TotalCnt EEMEM;
extern WORD  e_Options EEMEM;

extern char GetChar(void);
extern BYTE KeyPressed(void);
extern void Switch(WORD M, enum BITSTATE S);
extern void Pause(WORD T);
extern void SetPause(WORD T);
extern BYTE FeedSpeed(void);
extern DWORD AverageFeedSpeed(void);//was Byte
extern void Output(WORD D);
extern void InputInit(void);

#define PAUSE(T) Pause(T);
#define DELAY(T) SetPause(T);

#define RUNMOTOR   Flags = Flags & ~(F_Run | F_Back | F_Off) | F_Run;
#define BACKMOTOR  Flags = Flags & ~(F_Run | F_Back | F_Off) | F_Run | F_Back;
#define STOPMOTOR  Flags &= ~(F_Run | F_Back | F_NoCnt)
#define OFFMOTOR   Flags = Flags & ~(F_Run | F_Back) | F_Off
#define BACKMOTOR1 Flags = Flags & ~(F_Run | F_Back | F_Off) | F_Run | F_Back | F_NoCnt
#define RUNMOTOR1  Flags = Flags & ~(F_Run | F_Back | F_Off) | F_Run | F_NoCnt

#endif
